package com.wavehi.login.common;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @Description
 * @Author WaveHi
 * @Date 30/11/2021 下午 3:55
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 */
@Getter
@Setter
@ToString
public class AjaxResult<T> {

    public final static String CODE_SUCCESS = "200";
    public final static String MSG_SUCCESS = "请求成功";
    public final static String CODE_ERROR = "500";
    public final static String MSG_ERROR = "服务器错误";

    private String code;
    private String msg;
    private T data;

    private AjaxResult(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> AjaxResult success(T data) {
        return new AjaxResult(CODE_SUCCESS, MSG_SUCCESS, data);
    }
    public static AjaxResult success() {
        return new AjaxResult(CODE_SUCCESS, MSG_SUCCESS, null);
    }

    public static <T> AjaxResult error(String code, String msg, T data) {
        return new AjaxResult(code, msg, data);
    }
    public static AjaxResult error(String code, String msg) {
        return new AjaxResult(code, msg, null);
    }

}
